package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.GetOnlineCSCountBean;
import com.ymatou.iapi.sellercs.service.GetOnlineCSCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*获取子客服在线数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetOnlineCSCount{
	private static GetOnlineCSCountBean getonlinecscountBean;
	private static GetOnlineCSCountCall getonlinecscountCall;
	YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取子客服在线数");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		getonlinecscountBean=new GetOnlineCSCountBean();
		getonlinecscountCall=new GetOnlineCSCountCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getonlinecscountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetOnlineCSCount_001() {
		Logger.start(true,"获取子客服在线数成功");
		try {
			String SocketIoToken=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, zsellerId, SocketIoToken);
			Thread.sleep(1000);
			getonlinecscountBean.setSellerId(sellerId);
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("200", getonlinecscountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(1, getonlinecscountCall.getJsonObject().get("Result").getAsJsonObject().get("Count").getAsInt(), "验证Count");	
			SellerCSIMCallService.OffLine(zsellerId, SocketIoToken);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetOnlineCSCount_002() {
		Logger.start(true,"不输入sellerid失败");
		try {
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("400", getonlinecscountCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetOnlineCSCount_003() {
		Logger.start(true,"获取子客服在线数成功多人在线");
		try {
			String SocketIoToken=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, zsellerId, SocketIoToken);
			SellerCSIMCallService.AppLogin(zsellerId);
			Thread.sleep(1000);
			getonlinecscountBean.setSellerId(sellerId);
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("200", getonlinecscountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(1, getonlinecscountCall.getJsonObject().get("Result").getAsJsonObject().get("Count").getAsInt(), "验证Count");	
			SellerCSIMCallService.OffLine(zsellerId, SocketIoToken);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetOnlineCSCount_004() {
		Logger.start(true,"输入子客服id获取子客服在线数");
		try {
			String SocketIoToken=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.AppLogin(zsellerId);
			SellerCSIMCallService.OnLine(zsellerId);
			Thread.sleep(1000);
			getonlinecscountBean.setSellerId(zsellerId);
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("200", getonlinecscountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(0, getonlinecscountCall.getJsonObject().get("Result").getAsJsonObject().get("Count").getAsInt(), "验证Count");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetOnlineCSCount_005() {
		Logger.start(true,"获取子客服在线数成功,count不计算主账号");
		try {
			String SocketIoToken=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, sellerId, SocketIoToken);
			Thread.sleep(1000);
			getonlinecscountBean.setSellerId(sellerId);
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("200", getonlinecscountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(0, getonlinecscountCall.getJsonObject().get("Result").getAsJsonObject().get("Count").getAsInt(), "验证Count");	
			SellerCSIMCallService.OffLine(sellerId, SocketIoToken);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetOnlineCSCount_006() {
		Logger.start(true,"获取子客服在线数成功,子客服同时登入pc和app");
		try {
			String SocketIoToken=TestDataManager.getRandomUUID().toString();
			SellerCSIMCallService.PcLogin(sellerId, zsellerId, SocketIoToken);
			SellerCSIMCallService.AppLogin(zsellerId);
			SellerCSIMCallService.PcLogin(sellerId, sellerId, SocketIoToken);
			SellerCSIMCallService.AppLogin(sellerId);
			Thread.sleep(1000);
			getonlinecscountBean.setSellerId(sellerId);
			getonlinecscountCall.setData(getonlinecscountBean);
			getonlinecscountCall.callService();			
			Logger.verifyIsContains("200", getonlinecscountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(1, getonlinecscountCall.getJsonObject().get("Result").getAsJsonObject().get("Count").getAsInt(), "验证Count");	
			SellerCSIMCallService.OffLine(zsellerId, SocketIoToken);
			SellerCSIMCallService.OffLine(sellerId, SocketIoToken);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}